/*
 * @Description: 
 * @Author: zoe
 * @Date: 2024-09-13 17:31:58
 * @LastEditors: rendc
 * @LastEditTime: 2024-09-13 17:31:58
 */
public class Singleton {

    // 在类加载时就创建实例
    private static final Singleton instance = new Singleton();

    // 私有构造方法，防止外部创建实例
    private Singleton() {
        // 防止反射攻击
        if (instance != null) {
            throw new IllegalStateException("Singleton instance already exists.");
        }
    }

    // 提供一个全局访问点
    public static Singleton getInstance() {
        return instance;
    }

    // 示例方法
    public void displayMessage() {
        System.out.println("Hello, this is the singleton instance.");
    }
}
